<template>
  <div>
    <div class="head">
      <van-icon class="arrow-left" name="arrow-left" @click="goBack" /> 
      <p>注册</p>
    </div>

    <van-cell-group>
      <van-field
        v-model="value"
        placeholder="请输入手机号"
        @input="changelength"
        clearable
      />
    </van-cell-group>
    <br />
    <van-button :disabled="disabled"  type="primary" @click="goReg"
      >下一步</van-button
    >
  </div>
</template>

<script>
// import axios from "axios";
import {Toast} from "vant"
export default {
  name: "Reg",
  data() {
    return {
      value: "",
      disabled: true,
    };
  },
  
  methods: {
    goBack() {//返回
      this.$router.back();
    },
    // 验证手机号长度是否满足条件，满足取消禁用状态否则为禁用状态
    changelength() {
      if (this.value.length == 11) {
        this.disabled = false;
      } else {
        this.disabled = true;
      }
    },
    //注册手机号
    goReg() {
      this.$server
        .post("/api/user/docheckphone", {
          tel: this.value,
        })
        .then((res) => {
          console.log("res.data", res.data);
          if (res.data.code == 200) {
            this.$router.push(`/Regcode?tel=${this.value}`);
          }else{
            Toast("该手机号已经注册，请重新注册")
          }
        });
    },
  },
};
</script>

<style scoped>
.head {
  height: 45px;
  background-color: skyblue;
  text-align: center;
  line-height: 45px;
}
.arrow-left {
  float: left;
  margin: 1rem;
  color:blue
}
p{
  text-align: center;
  margin-right:42px
}
button {
  width: 20rem;
  height: 2.5rem;
  background: red;
  color: white;
  border: none;
  border-radius: 25px;
  margin-left: 1.2rem;
  margin-top: 1.5rem;
}
</style>
